<#assign classNameLower = className?uncap_first>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/pages/commons/path.jsp"%>

<script type="text/javascript">
	function isValid() {
		<#list table.columns as column>
		${'$'}('#${column.classColumnName}').validatebox({
			required : true,
			missingMessage : '请输入有效的${column.sqlRemarks}！'
		});
		if (!${'$'}('#${column.classColumnName}').validatebox('isValid'))
			return false;
		</#list>

		return true;
	}

	function save() {
		if (!isValid())
			return;
		<#list table.columns as column>
			var ${column.classColumnName} = ${'$'}.trim(${'$'}('#${column.classColumnName}').val());
		</#list>

		$.ajax({
			type : 'post',
			url : '${'$'}{ctx}${urlPath}/${classNameLower}/doAdd.do',
			data : {
				<#list table.columns as column>
					${column.classColumnName} : ${column.classColumnName}<#if column_has_next>,</#if>
				</#list>
			},
			dataType : 'json',
			success : function(data) {
				var result = data.result;
				if (result == 'success') {
					${'$'}.messager.alert('提示', '操作成功！', 'info');

					${'$'}('#editDiv').dialog('close');
					${'$'}('#dataTable').treegrid('reload');
					${'$'}('#dataTable').treegrid('clearChecked');
				} else {
					${'$'}.messager.alert('提示', '操作失败！<br />' + data.error, 'error');
				}
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				${'$'}.messager.alert('提示', '操作失败！<br />' + errorThrown, 'error');
			}
		});
	}
	
	function cancel() {
		${'$'}('#editDiv').dialog('close');
	}
</script>

<table class="table2">
	<#list table.columns as column>
	<tr>
		<td>${column.sqlRemarks}：</td>
		<td>
			<input id="${column.classColumnName}" type="text" style="width: 200px" />
		</td>
	</tr>
	</#list>	
	<tr>
		<td colspan="2" align="center">
			<a id="saveButton" class="easyui-linkbutton" icon="icon-ok" onclick="save()">确定</a>
			<a class="easyui-linkbutton" icon="icon-cancel" onclick="cancel()">取消</a>
		</td>
	</tr>
</table>